﻿
using IHISCETeim.BLL;
using IHISCETeim.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using IHISCETeim.Library;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace IHISCETeim.Web.MachineSys.SAPModel
{
    public partial class SAPBorrowEdit : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get { return "SAPBorrowList"; }
        }

        protected int BrwID
        {
            get
            {

                return GetRequestValue<int>("BrwID", 0);
            }
        }
        /// <summary>
        /// 操作方式
        /// </summary>
        protected string action
        {
            get
            {

                return GetRequestValue<string>("action", "View");
            }
        }



        private SAPBorrowInfo _obj = null;

        public SAPBorrowInfo obj
        {
            get
            {
                if (_obj == null)
                {
                    if (BrwID == 0)
                    {
                        _obj = new SAPBorrowInfo();
                    }
                    else {
                        _obj = SAPBorrowController.SAPBorrow_GetList(BrwID);
                    }
                }

                return _obj;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                add();
            }
            //JsonConvert.SerializeObject(obj)
            LoadInfo();
        }

        private void LoadInfo()
        {

            List<SAPBorrowReturnInfo> listParts = SAPBorrowController.SAPBorrowReturn_GetAll(BrwID);


            this.rpParts.DataSource = listParts;
            this.rpParts.DataBind();

        }
        private void add()
        {

            SAPBorrowReturnInfo objdetail = Request.SerializableObject<SAPBorrowReturnInfo>();
            objdetail.CreateDate = DateTime.Now;

            if (SAPBorrowController.SAPBorrowReturn_Add(objdetail) > 0)
            {
                SuccessJson(String.Format("已成功添加{0}记录.","归还"), this.DWZRef);
            }
            else {
                ErrorJson(String.Format("添加{0}记录失败！", "归还"));
            }



        }
    }
}